from py2neo import Graph
from py2neo.matching import *
from py2neo.ogm import GraphObject, Property, RelatedTo, RelatedFrom, Label

class Department(GraphObject):
    __primarykey__ = 'name'
    __primarylabel__ = '科室'
    name = Property()

class Food(GraphObject):
    __primarykey__ = 'name'
    __primarylabel__ = '食物'
    name = Property()

class S(GraphObject):
    __primarykey__ = 'name'
    __primarylabel__ = '症状'
    name = Property()

class Drug(GraphObject):
    __primarykey__ = 'name'
    __primarylabel__ = '药品'
    name = Property()

class Disease(GraphObject):
    __primarykey__ = 'name'
    __primarylabel__ = '疾病'

    name = Property()
    departs = RelatedTo(Department, 'cure_department')
    foods = RelatedTo(Food, 'do_eat')
    drugs = RelatedTo(Drug, 'recommand_drug')
    symptoms = RelatedTo(S, 'has_symptom')
    
class Symptom(GraphObject):
    __primarykey__ = 'name'
    __primarylabel__ = '症状'
    name = Property()
    diseases = RelatedFrom(Disease, 'has_symptom')


    

if __name__ == "__main__":
    g = Graph(password='neo4j')
    # dis = Disease.match(g).where(name='肺炎').first()
    sym1 = Symptom.match(g).where(name='流鼻涕').first()
    dis1 = set(d.name for d in sym1.diseases)
    sym2 = Symptom.match(g).where(name='发烧').first()
    dis2 = set(d.name for d in sym2.diseases)
    sym3 = Symptom.match(g).where(name='打喷嚏').first()
    dis3 = set(d.name for d in sym3.diseases)
    print(dis1 & dis2 & dis3)
    
    # print(dep.do_eat)
    # print([f.name for f in dis.foods])
    # print([d.name for d in dis.drugs])
    # print([s.name for s in dis.symptoms])